﻿using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using WebShopData;

namespace AdminTools
{
    public partial class OrderDetailsForm : Form
    {
        public int OrderNumber { get; set; }
        public OrderDetailsForm(int orderid)
        {
            InitializeComponent();
            if (orderid >= 0)
                OrderNumber = orderid;
            else
                MessageBox.Show("Invalid ordernumber");
        }

        private void backgroundWorkerLoadOrder_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            DataSet dataset = WebShopDal.GetOrderOverviewSingleOrder(OrderNumber);
            dataGridViewOrderview.DataSource = dataset.Tables[0];
            Debug.Print("backgroundWorkerLoadOrder_DoWork");
        }


        private void OrderDetailsForm_Load(object sender, System.EventArgs e)
        {
            RefreshOrder();
        }

        private void dataGridViewOrderview_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            WebShopDal.SetOrderToProcessed(true, OrderNumber);
            RefreshOrder();
        }

        private void RefreshOrder()
        {
            backgroundWorkerLoadOrder_DoWork(null, null); ;
        }

        private void buttonNotProcessed_Click(object sender, System.EventArgs e)
        {
            WebShopDal.SetOrderToProcessed(false, OrderNumber);
            RefreshOrder();
        }
    }
}
